package institutional

class Subject {
	int code
	String name
	int credits
	int hoursPerWeek
	
	static belongsTo = [department: Department]
	static hasMany = [courses: Course]

	
    static constraints = {
		code (unique: 'department')
		name(nullable: false)
		credits(nullable: false)
		hoursPerWeek(nullable: false)
    }
	
	String toString () {
		String s = getSubjectCode()+" $name";
		return s
	}
	
	String getSubjectCode() {
		String s = department.getCode()+"."+ String.format("%02d", code) 
		return s
	}
}
